<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>
    <script src="https://cdn.bootcdn.net/ajax/libs/react/17.0.1/umd/react.development.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.1/umd/react-dom.development.min.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
    <script type="text/babel">
      const { Component } = React;

      class Login extends Component {
        state = { username: "", password: "" };
        handleSaveFormData = (dataType, event) =>
          this.setState({ [dataType]: event.target.value });

        handleSubmit = (event) => {
          event.preventDefault();
          const { username, password } = this.state;
          alert(`当前用户名${username} 和密码是${password}`);
        };
        render() {
          return (
            <div>
              <form action="www.baidu.com" onSubmit={this.handleSubmit}>
                <input
                  onChange={(event) =>
                    this.handleSaveFormData("username", event)
                  }
                  type="text"
                  name="username"
                />
                <input
                  onChange={(event) =>
                    this.handleSaveFormData("password", event)
                  }
                  type="password"
                  name="password"
                />
                <button>提交</button>
              </form>
            </div>
          );
        }
      }

      const App = (
        <div>
          <Login />
        </div>
      );
      ReactDOM.render(App, document.getElementById("root"));
    </script>
  </body>
</html>
